
package com.hmsg.health.dao;

import com.hmsg.health.bean.domain.UserAccountDo;
import com.hmsg.health.bean.domain.UserDo;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserAccountDao {
    @Select("select * from s_user_account where id=#{id}")
    UserAccountDo select(@Param("id")Integer id);
    
    @Select("select * from s_user_account where user_id=#{userid}")
    UserAccountDo selectByUserId(Integer userid);
  
    @Insert("<script>" +
    "insert into `s_user_account` " +
    "  <set>" +
    "    <if test='info.userId != null'>" +
    "     `user_id` = #{info.userId}, " +
    "    </if>" +
    "    <if test='info.glod != null'>" +
    "      `glod` = #{info.glod}, " +
    "    </if>" +
    "    <if test='info.canWithdraw != null'>" +
    "      `can_withdraw` = #{info.canWithdraw}, " +
    "    </if>" +
    "    <if test='info.score != null'>" +
    "      `score` = #{info.score} " +
    "    </if>" +
   
    "  </set>" +
    "</script>")
	@Options(useGeneratedKeys = true, keyProperty = "id")
	int save(@Param("info") UserAccountDo info);


    @Update({"<script>",
		"UPDATE  s_user_account",
			"<trim prefix='set' suffixOverrides=','>",
		
		"<if test='user.glod!=null'>",
		"glod= #{user.glod},",
		"can_withdraw= #{user.glod}/100,",
		"</if>",
		
		"<if test='user.score!=null'>",
		"score= #{user.score}",
		"</if>",
	
		"</trim>",
		"where id = #{user.id}",
		"</script>"})
 	Integer update(@Param("user") UserAccountDo user);


	@Select("select * from s_user_account where user_id=#{userId}")
	UserAccountDo findUserAccount(@Param("userId") Integer userId);


	@Update({"<script>",
			"UPDATE  s_user_account",
			"<trim prefix='set' suffixOverrides=','>",

			"<if test='taskGold!=null'>",
			"glod= #{taskGold},",
			"</if>",
			"</trim>",
			"where user_id = #{userId}",
			"</script>"})
	void updateByUserId(@Param("userId") Integer userId, @Param("taskGold") Integer taskGold);


	@Update("update s_user_account set glod=glod-#{taskGold} where user_id=#{userId}")
	void updateTaskGold(@Param("userId") Integer userId, @Param("taskGold") Integer taskGold);
}